import threading
from time import sleep,ctime
loops=[4,2]
class MyThread(threading.Thread):
	def __init__(self,func,args,name=''):
		threading.Thread.__init__(self)
		self.name = name
		self.func = func
		self.args = args
	def run(self):
		self.func(*self.args)
def loop(nloop,nsec):
	print('开始循环',nloop,'在：',ctime())
	sleep(nsec)
	print('结束循环',nloop,'于：',ctime())
def main():
	print('程序开始于：',ctime())
	threads = []
	nloops = range(len(loops))
	for i in nloops:
		t = MyThread(loop,(i,loops[i]),loop.__name__)
		threads.append(t)
	for i in nloops:
		threads[i].start()
	for i in nloops:
		threads[i].join()
	print('所有的任务完成于：',ctime())
if __name__ =='__main__':
	main()